﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Routed_Event {
    /// <summary>
    /// Lógica de interacción para MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window {

        public static readonly RoutedEvent clickEvent = EventManager.RegisterRoutedEvent("clickEvent", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MainWindow));

        public event RoutedEventHandler clickEventProp {
            add { 
                this.AddHandler(clickEvent, value); 
            }
            remove { 
                this.RemoveHandler(clickEvent, value); 
            }
        
        }

        
        public MainWindow() {
            InitializeComponent();
            RoutedEventArgs rea = new RoutedEventArgs(MainWindow.clickEvent);
            clickEventProp += mm;
            RaiseEvent(rea);
 }

        private void textBox1_TextChanged(object sender, TextChangedEventArgs e) {

            //MessageBox.Show("Raised by the textbox");
            e.Handled = (bool)radioButton1.IsChecked;
        }

        private void Grid_TextChanged(object sender, TextChangedEventArgs e) {

            //MessageBox.Show("Raised by the Grid");
            e.Handled = (bool)radioButton2.IsChecked;
        
        }

        private void Window_TextChanged(object sender, TextChangedEventArgs e) {
            //MessageBox.Show("Raised by the Window");
            e.Handled = (bool)radioButton3.IsChecked;
        
        }

        public void mm(Object sender,RoutedEventArgs arg){
            //MessageBox.Show("CUstom Event");
        }

        private void textBox1_PreviewTextInput(object sender, TextCompositionEventArgs e) {
            //MessageBox.Show("textBox Preview");
            MessageBox.Show(e.TextComposition.Text);
            Double d = Double.Parse(e.Text);

            if (d > 100) {

            } else {
                e.Handled = true;
            }


        
        }

        private void Grid_TextInput(object sender, TextCompositionEventArgs e) {
          
            
            //if(e.Source.GetType().Equals(typeof(TextBox))){
            //    TextBox tt = (TextBox)e.Source;
            //    if (tt.Name == "uno") { 
                
            //    }
            
            //}


            // MessageBox.Show("Grid Preview");
            String aux = e.Text;
           //MessageBox.Show(aux);
            try { Double d = Double.Parse(aux);
            } catch (Exception ex) {
                e.Handled = true;
            }
        }

        private void textBox2_PreviewTextInput(object sender, TextCompositionEventArgs e) {

        }

        private void textBox2_TextChanged(object sender, TextChangedEventArgs e) {

        }
    }
}
